#include "MephistoCAM.h"

#define REG_NUM CCD290_DRV_CONFIG_PARAM_NUM

int main( int argc, char *argv[] ){

    if( argc < 2 ){
        printf("usage: %s ccd290_drive_cfg.ini\n", argv[0]);
        return 0;
    }

    printf("> ********************************************************************\n");
    printf("> This is new version of CCD290 readout drive configuration programm.\n");
    printf("> ********************************************************************\n");

    char ini_fname[256];
    sprintf(ini_fname, "%s", argv[1]);

    ccd290_drive_config cfg;
    load_ccd290_drive_config_params( ini_fname, &cfg );

    print_ccd290_drive_config_params( &cfg );   // for debug

    uint32_t reg_vals[REG_NUM] = {0};

    extract_ccd290_drive_config_params( &cfg, reg_vals );


    int fd = open("/dev/mem", O_RDWR | O_SYNC);
    uint32_t *ptr = mmap(NULL, 10, PROT_READ | PROT_WRITE, MAP_SHARED, fd, ADDR_GPIO_SPI_PS_CTRL);
    uint32_t *ctrl_reg = ptr;       // 0x41230000
    uint32_t *data_reg = ptr + 2;   // 0x41230008

    SPI_PS_SEND_DATA_new(   ctrl_reg,
                            data_reg, 
                            reg_vals, 
                            REG_NUM,
                            SPI_PS_READOUT_DRV );

    munmap(ptr,10);
    close(fd);

    return 0;
}
